package scripts.sea;

import api.sea.LoginApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import util.*;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 登录
 */
public class TestLogin {
    private static final Logger logger= LoggerFactory.getLogger(TestLogin.class);
    @DataProvider
    public Object[][] build_data() throws IOException {
        String key="username,password";
        Object[][] test_data = TestDataUtil.build_data("adminlogin.json", key);
        logger.info("test_data={}", Arrays.deepToString(test_data));
        return test_data;
    }
    @Test(dataProvider = "build_data")
    public static void test_01(String username,String password) throws IOException, URISyntaxException {
        ResponseData responseData= LoginApi.login(username,password);
        Assert.assertEquals(responseData.getBody().get("msg"),"登陆成功");
        logger.info("状态码={}",responseData.getCode());
        logger.info("登录token={}",responseData.getBody().getJSONObject("data").getString("logistics-token"));
        String data = responseData.getBody().getJSONObject("data").getString("logistics-token");
        HttpClientUtils.build_header("logistics-token",data);
        AssertUtil.assertCommon(responseData,0,"登陆成功");
    }

}
